package com.application.viewmodel;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

public class LoginViewModel extends ViewModel {

    public final MutableLiveData<String> username = new MutableLiveData<>("");
    public final MutableLiveData<String> password = new MutableLiveData<>("");
    public final MutableLiveData<Boolean> rememberPassword = new MutableLiveData<>(false);
    public final MutableLiveData<Boolean> autoLogin = new MutableLiveData<>(false);

    public boolean validateLogin() {
        String user = username.getValue();
        String pwd = password.getValue();

        if (user == null || user.trim().isEmpty()) {
            return false;
        }
        if (pwd == null || pwd.isEmpty()) {
            return false;
        }
        return true;
    }

    public String errorMessage() {
        String user = username.getValue();
        String pwd = password.getValue();

        if (user == null || user.trim().isEmpty()) {
            return "请输入用户名或手机号";
        }
        if (pwd == null || pwd.isEmpty()) {
            return "请输入密码";
        }
        return "";
    }


}
